fix: Fixes Stack Overflow and Memory Management Issues #542
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've made some improvements to address stack overflow issues and enhance memory management.
Key Changes:
Increased Stack Size:
The stack size has been increased to 2048 bytes for
overflow_stack
and 8192 bytes forallocate_stack_with_increased_size
to prevent stack overflow errors. These values can be adjusted as per your system requirements.Replaced Array with Vec:
The static array in
overflow_stack
has been replaced with a dynamicVec<u32>
, which allocates memory on the heap, eliminating the risk of stack overflow.Memory Management in
overflow_heap
:I introduced a variable to track the allocated memory in
overflow_heap
. Additionally, I added an exit condition when the total allocated memory exceeds 100MB to prevent infinite memory allocation.Optimized
memory_size
Attribute:The
memory_size
attribute in#[jolt::provable(memory_size = 8192)]
has been updated to 8MB, allowing the function to handle larger memory sizes, which is particularly useful when allocating multiple vectors.These changes should resolve the stack overflow and memory issues, improving stability.